#pragma once


#include <sys/epoll.h>
#include "log.hpp"

class Epoller
{
static const int size = 128;
public:
    Epoller()
    {
        _epfd = epoll_create(size);
        if(_epfd < 0)
        {
            lg(Fatal, "epoll create err, epfd: %d", _epfd);
        }
        else
        {
            lg(Info, "epoll create success, epfd: %d", _epfd);
        }
    }

    ~Epoller()
    {}

    int EpollWait(struct epoll_event* envents, int num, int timeout)
    {
        int ret = epoll_wait(_epfd, envents, num, timeout);
        
        return ret;
    }

    int  EpollUpdate(int op, int fd, int event)
    {
        if(op & EPOLL_CTL_ADD)
        {
            struct epoll_event evt;
            evt.data.fd = fd;
            evt.events = event;

            int ret = epoll_ctl(_epfd, op, fd, &evt);
            
        }
        else if(op & EPOLL_CTL_DEL)
        {
            int ret = epoll_ctl(_epfd, op, fd, nullptr);
        }
    }
private:
    int _epfd;
};